package com.zksk.admin.mapper.member;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zksk.admin.domain.market.dto.SaleMemberDto;
import com.zksk.admin.domain.member.vo.MemberVo;
import com.zksk.mbg.admin.domain.Member;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;

/**
 * @description:
 * @author: xiebo
 * @create: 2022-12-28 17:35
 **/
@Mapper
public interface MemberDao extends BaseMapper<Member>
{

    @Update("UPDATE platform_fact_member SET sale_user = #{saleUser},sale_username = #{saleUsername},plan_time = #{localDateTime},if_sale = 1 WHERE member_id = #{id}")
    Integer distribution(Long id, Long saleUser, String saleUsername, LocalDateTime localDateTime);

    @Select("SELECT\n" +
            "\tm.member_id,\n" +
            "\tm.member_name,\n" +
            "\tm.member_code,\n" +
            "\tm.member_type,\n" +
            "\tm.member_level,\n" +
            "\tm.sale_user,\n" +
            "\tm.sale_username,\n" +
            "\tm.if_sale,\n" +
            "\tm.plan_time,\n" +
            "\tm.channel_id,\n" +
            "\tm.channel_name,\n" +
            "\tm.`status`,\n" +
            "\tm.credit_code,\n" +
            "\tm.address,\n" +
            "\tm.phone,\n" +
            "\tm.reg_money,\n" +
            "\tm.trade_type,\n" +
            "\tm.legal_name,\n" +
            "\tm.legal_phone,\n" +
            "\tm.bank_name,\n" +
            "\tm.open_bank,\n" +
            "\tm.bank_account,\n" +
            "\tm.open_bank_file,\n" +
            "\tm.bus_certificate,\n" +
            "\tm.legal_code,\n" +
            "\tm.stations_id,\n" +
            "\tm.stations_name,\n" +
            "\tm.storage_time,\n" +
            "\tm.remark,\n" +
            "\to.operator_name,\n" +
            "\to.operator_phone \n" +
            "FROM\n" +
            "\tplatform_fact_member AS m\n" +
            "INNER JOIN \n" +
            "\tplatform_fact_member_operator AS o \n" +
            "\tON m.member_id = o.member_id \n" +
            "\tAND m.del_flag = 0 \n" +
            "\tAND o.del_flag = 0 \n" +
            "\tAND o.default_op = 0 \n" +
            "\t ${ew.customSqlSegment}")
    Page<MemberVo> selectPageList(Page<Member> page, @Param(Constants.WRAPPER) Wrapper<Member> wrapper);


    /**
     * 营销模块 分配用户列表
     * @param page
     * @param wrapper
     * @return
     */
    Page<SaleMemberDto> marketingMemberList(Page<Member> page, @Param(Constants.WRAPPER) QueryWrapper<Member> wrapper);
}